package cn.com.customer.manager.base;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * ============================================
 * 文件名：BaseApplication.java
 * ============================================
 */
public class BaseApplication extends Application {
    private static final String PREF_NAME = "config.pref";
    private static Context _context;

    @Override
    public void onCreate() {
        super.onCreate();

        _context = getApplicationContext();
    }

    public static synchronized Context getContext() {
        return _context;
    }

    public static void set(String key, int value) {
        SharedPreferences.Editor editor = getPreferences().edit();
        editor.putInt(key, value);
        editor.commit();
    }

    public static void set(String key, Long value) {
        SharedPreferences.Editor editor = getPreferences().edit();
        editor.putLong(key, value);
        editor.commit();
    }

    public static void set(String key, boolean value) {
        SharedPreferences.Editor editor = getPreferences().edit();
        editor.putBoolean(key, value);
        editor.commit();
    }

    public static void set(String key, String value) {
        SharedPreferences.Editor editor = getPreferences().edit();
        editor.putString(key, value);
        editor.commit();
    }

    public static boolean get(String key, boolean defValue) {
        return getPreferences().getBoolean(key, defValue);
    }

    public static String get(String key, String defValue) {
        return getPreferences().getString(key, defValue);
    }

    public static int get(String key, int defValue) {
        return getPreferences().getInt(key, defValue);
    }

    public static long get(String key, long defValue) {
        return getPreferences().getLong(key, defValue);
    }

    public static float get(String key, float defValue) {
        return getPreferences().getFloat(key, defValue);
    }

    public static void remove(String key) {
        SharedPreferences.Editor editor = getPreferences().edit();
        editor.remove(key);
        editor.commit();
    }
    public static void removeAll(){
        SharedPreferences.Editor editor = getPreferences().edit();
        editor.clear();
        editor.commit();
    }
    public static SharedPreferences getPreferences() {
        return getContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    }
}
